package com.example.sxt_practise.java并发编程;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author gaofeng
 * date 2022年01月03日 10:48
 */
public class TestFutureTask {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // FutureTask可以接收Callable类型的参数,用来处理有返回值的情况
        FutureTask futureTask = new FutureTask<Integer>(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                return 100;
            }
        });

        Thread thread = new Thread(futureTask, "gao3");
        thread.start();
        // 阻塞,一直等待结果返回
        Integer o = (Integer) futureTask.get();
        System.out.println("执行结果是" + o);
    }
}
